import { ProTableColumn } from '@/components/pro-table/type'
import { NButton, NPopconfirm } from 'naive-ui'
import { WarehouseModel } from '@/api/model/sys/warehouse-model'

type Props = {
  handleEditWarehouse: (row: WarehouseModel) => void
  fetchDelWarehouse: (id: number) => void
}

export const useWarehouseProTable = ({
  handleEditWarehouse,
  fetchDelWarehouse
}: Props) => {
  const columns: ProTableColumn<WarehouseModel>[] = [
    {
      title: '地址名称',
      key: 'warehouseName'
    },
    {
      title: '创建时间',
      key: 'createdDate'
    },
    {
      title: '备注',
      key: 'remark'
    },
    {
      title: '操作',
      key: 'operation',
      render(row) {
        return (
          <>
            <NButton
              type="primary"
              size="small"
              onClick={() => handleEditWarehouse(row)}
              quaternary
            >
              修改
            </NButton>
            <NPopconfirm onPositiveClick={() => fetchDelWarehouse(row.id)}>
              {{
                trigger: () => (
                  <NButton size="small" type="error" quaternary>
                    删除
                  </NButton>
                ),
                default: () => '您确定要删除？'
              }}
            </NPopconfirm>
          </>
        )
      }
    }
  ]

  return {
    columns
  }
}
